<?php
session_start();
require_once('m_ajax.php');
	
	$uid = $_POST['uid'];
	$answer_id = $_POST['answer_id'];
	$poll_id = $_POST['poll_id'];
	$today = date("Y-m-d");
	
	//Check if user has already voted today
	$sql = "select id from poll_votes where date_voted='$today' and user_id=$uid and question_id=$poll_id";
    $result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	
	if(empty($row))//if this is empty user hasn't voted
	{
		$sql = "insert into poll_votes (question_id,answer_id,user_id,date_voted) values ($poll_id,$answer_id,$uid,'$today')";
		mysql_query($sql);
		$data['message'] = "thanks for voting";
	}
	else
	{
		$data['message'] = "you have already voted for today try again tomorrow";
	}
	

echo json_encode($data);
?>